<?php


namespace App\Http\Middleware;


use App\AppContext\Admin;
use Closure;
use Illuminate\Support\Facades\App;

class AdminContext
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $lang = $request->cookie('lang', '');
        if (!empty($lang)) {
            App::setLocale($lang);
        }
        app()->singleton("AppContext", Admin::class);
        return $next($request);
    }
}
